<template>
 <!-- 主体部分 -->
    <section class="main">
      <input v-model="checkAll" id="toggle-all" class="toggle-all" type="checkbox" />
      <label for="toggle-all">Mark all as complete</label>
      <ul class="todo-list">
        <!-- 当任务已完成，可以给 li 加上 completed 类，会让元素加上删除线 -->
        <li v-for="item in list" 
        :key="item.id" 
        :class="{completed: item.isDone}">
          <div class="view">
            <input   @change="changeId(item.id)" class="toggle" type="checkbox" :checked="item.isDone" />
            <label>{{item.name}}</label>
            <button @click="delData(item.id)" class="destroy"></button>
          </div>
        </li>
      </ul>
    </section>
</template>

<script>
export default {
  name: 'TodoMain',
  //父传子将list数组传输过来
 props: {
    list: {
      type: Array,
      required: true
    }
  },
  data() {
    return {
      
    };
  },
   computed:{
    checkAll:{
      get(){
        return this.list.every(item=>item.isDone)
      },
      set(val){
       return this.$emit('allCheck',val)
      }
    }
  },
  methods: {
  //将id通过子传父传给app.vue
  delData(id){
    this.$emit('delTask',id)
  },
   //修改任务列表状态
   changeId(id){
    this.$emit('changeTask',id)

   }

  },
};
</script>

<style lang="scss" scoped>

</style>